import { lazyReportBatch } from "../report";
export default function observerPaint() {
  const entryHandler = (list) => {
    for (const entry of list.getEntries()) {
      if (entry.name === "first-paint") {
        observerr.disconnect();
        const json = entry.toJSON();
        console.log(json);
        const reportData = {
          ...json,
          type: "performance",
          pageUrl: window.location.href,
          subType: entry.name,
          pageUrl: window.location.href,
        };

        // 发送数据 todo
        console.log(reportData);
        lazyReportBatch(reportData);
      }
    }
  };

  // 统计和计算fp的时间
  const observerr = new PerformanceObserver(entryHandler);

  // buffered: true 确保观测到所有paint时间
  observerr.observe({ type: "paint", buffered: true });
}
